package com.lt.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.crm.pojo.BasDict;
import com.lt.crm.pojo.CstCustomer;
import com.lt.crm.service.BasDictService;
import com.lt.crm.service.CstCustomerService;
import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Resource
    CstCustomerService cstCustomerService;

    @Resource
    BasDictService basDictService;

    @RequestMapping(value = "/list")
    public String list(Model model, String custName, String custRegion,
                       @RequestParam(required = false, defaultValue = "1") int pageIndex) {
//        System.out.println("名称为:" + custName);
//        Sort sort = Sort.by(Sort.Direction.ASC, "custNo");
//        //控制分页的辅助类，可以设置页码(从0开始！！！)、每页的数据条数、排序等
//        Pageable pageable = PageRequest.of(pageIndex - 1, 3, sort);
        Page<CstCustomer> page = new Page<>(pageIndex, 5);
        Page<CstCustomer> customerPager = cstCustomerService.findCustomer(custName, custRegion, page);
        model.addAttribute("page", customerPager);
        model.addAttribute("custName", custName);
        model.addAttribute("custRegion", custRegion);
        QueryWrapper<BasDict> queryWrapper = new QueryWrapper();
        queryWrapper.eq("dict_type","地区");
        List<BasDict> dictList = basDictService.list(queryWrapper);
        model.addAttribute("dictList", dictList);
        return "customer/list";
    }

    @RequestMapping(value = "/edit")
    public String edit(String customercId, Model model) {
        System.out.println(customercId);
        return "customer/edit";
    }
}
